	
	package service;
	
	import java.util.ArrayList;
	import java.util.List;
	import Dao.UserDao;
import Dao.daoimpl.UserDaoImpl;
import enitys.User;
	
	/**
	 * 单例模式
	 * 
	 */
	public class UserManager {
		private UserDao dao=new UserDaoImpl();
		static private UserManager instance = null;
	
		private UserManager() {
	
		}
	
		static public synchronized UserManager getInstance() {
			if (instance == null) {
				instance = new UserManager();
			}
			return instance;
		}
	
		public boolean Login(String name,String password,int shenfen) {//处理登录结果
			boolean flag = false;
			try {
				flag = dao.CheckLogin(name, password,shenfen);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return flag;
		}
	
		public boolean register(User user) {//处理注册
			boolean flag = false;
			try {
				flag = dao.userRegister(user);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
			return flag;
		}
	
		public List<User> find() {//返回全部人的信息
			List<User> list = new ArrayList<User>();
			try {
				list = dao.findUser();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;
		}
		public User getUserById(int s_id){//通过ID查找所有的信息
			User user=new User();
			try {
				user=dao.getuserById(s_id);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return user;
			
		}
		public User getUserByName(String name) throws Exception{
			User user=new User();
			user=dao.findUserByName(name);
			return user;//通过ID查找所有的信息
			
		}
		public boolean  modifyUser(User user,int id){//修改信息
			boolean result=false;
			try {
				result=dao.modfiyUser(user,id);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return result;
		}
		public int deleteUser(int id){//删除信息
			int result=0;
			try {
				result=dao.deleteUser(id);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return result;
		}
	
	}
